import { deletes, get, getBaseURL, post } from './request'
const HttpManager = {
  // 获取图片信息
  // attachImageUrl: (url) => `${getBaseURL()}/${url}`,
  attachImageUrl: (url) => {
    if (url) {
      if (url.startsWith("https://")) {
        return url;
      } else {
        return `${getBaseURL()}/${url}`;
      }
    } else {
      return "https://cube.elemecdn.com/e/fd/0fc7d20532fdaf769a25683617711png.png";
    }
  },
  // =======================> 管理员 API 完成
  // 是否登录成功
  // 是否登录成功
  getLoginStatus: ({ username, password }) => post(`admin/login/status`, { username, password }),

  // =======================> 用户 API 完成
  // 返回所有用户
  getAllUser: (curPage, pageSize) => get(`user?curPage=` + curPage + '&pageSize=' + pageSize),
  // 首页获取用户数
  getUsers: () => get(`users`),
  // 返回指定ID的用户
  getUserOfId: (id) => get(`user/detail?id=${id}`),
  // 删除用户
  deleteUser: (id) => get(`user/delete?id=${id}`),
  //删除多个用户
  deleteUsers: (ids) => deletes(`user/deleteIds?${ids}`),

  // =======================> 收藏列表 API 完成
  // 返回的指定用户ID收藏列表
  getCollectionOfUser: (userId) => get(`collection/detail?userId=${userId}`),
  // 删除收藏的歌曲
  deleteCollection: (userId, songId) => deletes(`collection/delete?userId=${userId}&&songId=${songId}`),

  // =======================> 评论列表 API 完成
  // 获得指定歌曲ID的评论列表
  getCommentOfSongId: (songId) => get(`comment/song/detail?songId=${songId}`),
  // 获得指定歌单ID的评论列表
  getCommentOfSongListId: (songListId) => get(`comment/songList/${songListId}`),
  //getCommentOfSongListId: (songListId) => get(`comment/songList/detail?songListId=${songListId}`),
  // 删除评论
  deleteComment: (id) => get(`comment/delete?id=${id}`),

  // =======================> 歌手 API 完成
  // 返回所有歌手
  getAllSinger: () => get(`singer`),
  // 添加歌手
  setSinger: ({ name, sex, birth, location, introduction }) => post(`singer/add`, {
    name,
    sex,
    birth,
    location,
    introduction
  }),
  // 更新歌手信息
  updateSingerMsg: ({ id, name, sex, birth, location, introduction }) => post(`singer/update`, {
    id,
    name,
    sex,
    birth,
    location,
    introduction
  }),
  // 删除歌手
  deleteSinger: (id) => deletes(`singer/delete?id=${id}`),

  // =======================> 歌曲 API  完成
  // 返回所有歌曲
  getAllSong: () => get(`song`),
  // 返回指定歌手ID的歌曲
  getSongOfSingerId: (id) => get(`song/singer/detail?singerId=${id}`),
  // 返回的指定用户ID收藏列表
  getSongOfId: (id) => get(`song/detail?id=${id}`),
  // 返回指定歌手名的歌曲
  getSongOfSingerName: (id) => get(`song/singerName/detail?name=${id}`),
  // 更新歌曲信息
  updateSongMsg: ({ id, singerId, name, introduction, lyric }) => post(`song/update`, {
    id,
    singerId,
    name,
    introduction,
    lyric
  }),
  updateSongUrl: (id) => `${getBaseURL()}/song/url/update?id=${id}`,
  updateSongImg: (id) => `${getBaseURL()}/song/img/update?id=${id}`,
  // 删除歌曲
  deleteSong: (id) => deletes(`song/delete?id=${id}`),

  // =======================> 歌单 API 完成
  // 添加歌单
  setSongList: ({ title, introduction, style }) => post(`songList/add`, { title, introduction, style }),
  // 获取全部歌单
  getSongList: (style) => get(`songList?style=${style}`),
  // 更新歌单信息
  updateSongListMsg: ({ id, title, introduction, style }) => post(`songList/update`, { id, title, introduction, style }),
  // 删除歌单
  deleteSongList: (id) => get(`songList/delete?id=${id}`),

  // =======================> 歌单歌曲 API 完成
  // 给歌单添加歌曲
  setListSong: ({ songId, songListId }) => post(`listSong/add`, { songId, songListId }),
  // 返回歌单里指定歌单ID的歌曲
  getListSongOfSongId: (songListId) => get(`listSong/detail?songListId=${songListId}`),
  // 删除歌单里的歌曲
  deleteListSong: (songId) => get(`listSong/delete?songId=${songId}`)

}

export { HttpManager }
